package com.yfqy.admin.exception;

import com.yfqy.admin.enums.ResponseEnum;
import lombok.Data;
import lombok.EqualsAndHashCode;

@Data
@EqualsAndHashCode(callSuper = true)
public class BaseException extends RuntimeException {

    private static final long serialVersionUID = -7972131521045668011L;

    /**
     * 自定义异常码
     */
    private Integer code;

    /**
     * 已知的异常信息
     */
    private String message;

    /**
     * 请求url
     */
    private String path;

    /**
     * get,post,...
     */
    private String method;

    private BaseException() {
    }

    public BaseException(Integer code, String message, String path, String method) {
        this.code = code;
        this.message = message;
        this.path = path;
        this.method = method;
    }

    public static BaseException fail(Integer code, String message) {
        return fail(code, message, "", "");
    }

    public static BaseException fail(ResponseEnum exceptionEnum) {
        return fail(exceptionEnum.getCode(), exceptionEnum.getMessage(), "", "");
    }

    public static BaseException fail(ResponseEnum exceptionEnum, String path, String method) {
        return fail(exceptionEnum.getCode(), exceptionEnum.getMessage(), path, method);
    }

    public static BaseException fail(Integer code, String message, String path, String method) {
        return new BaseException(code, message, path, method);
    }

}